﻿@{
    Html.EnableClientValidation();
    Html.EnableUnobtrusiveJavaScript();

    var grid = @Html.DevExpress().GridView(
        settings => {
            settings.Name = "detailGridViewVista_" + ViewData["IdPedido"];
            settings.CallbackRouteValues = new { Controller = "Pedidos", Action = "EditPedidoDetallePartial", IdPedido = ViewData["IdPedido"] };
            
            settings.Width = System.Web.UI.WebControls.Unit.Percentage(60);
            settings.KeyFieldName = "IdDetallePedido";

            settings.Columns.Add(
                column =>
                {
                    column.FieldName = "Producto.Nombre";
                    column.Caption = "Producto";
                    column.Width = 180;
                });
            
            settings.Columns.Add("Cantidad");
            settings.Columns.Add("Producto.Unidad.Nombre").EditFormSettings.Visible = DevExpress.Utils.DefaultBoolean.False;


            settings.Columns.Add(column =>
            {
                column.FieldName = "Producto.PrecioLista";
                column.Caption = "P sin IVA";

                column.ColumnType = MVCxGridViewColumnType.SpinEdit;
                column.Width = 100;
                var spinEditProperties = column.PropertiesEdit as SpinEditProperties;
                spinEditProperties.DisplayFormatString = "c";
                spinEditProperties.DisplayFormatInEditMode = true;
                column.EditFormSettings.Visible = DevExpress.Utils.DefaultBoolean.False;
            });

            settings.Columns.Add(column =>
            {
                column.FieldName = "Producto.Alicuota";
                column.Caption = "% IVA";

                column.ColumnType = MVCxGridViewColumnType.SpinEdit;
                column.Width = 50;
                column.EditFormSettings.Visible = DevExpress.Utils.DefaultBoolean.False;
            });

            settings.Columns.Add(column =>
            {
                column.FieldName = "Producto.PrecioConIva";
                column.Caption = "P con IVA";

                column.ColumnType = MVCxGridViewColumnType.SpinEdit;
                column.Width = 100;
                var spinEditProperties = column.PropertiesEdit as SpinEditProperties;
                spinEditProperties.DisplayFormatString = "c";
                spinEditProperties.DisplayFormatInEditMode = true;
                column.EditFormSettings.Visible = DevExpress.Utils.DefaultBoolean.False;
            });

            settings.Columns.Add(column =>
            {
                column.FieldName = "TotalRenglon";
                column.Caption = "TotalRenglon";

                column.ColumnType = MVCxGridViewColumnType.SpinEdit;
                column.Width = 100;
                var spinEditProperties = column.PropertiesEdit as SpinEditProperties;
                spinEditProperties.DisplayFormatString = "c";
                spinEditProperties.DisplayFormatInEditMode = true;
                column.EditFormSettings.Visible = DevExpress.Utils.DefaultBoolean.False;
            });
            
            settings.Columns.Add(
                column =>
                {
                    column.FieldName = "Estado";
                    column.Caption = "Estado";
                });

            settings.Settings.ShowFooter = true;
            settings.TotalSummary.Add(DevExpress.Data.SummaryItemType.Sum, "TotalRenglon");
            settings.TotalSummary.Add(DevExpress.Data.SummaryItemType.Sum, "Cantidad");
            
         });

    if (ViewData["EditError"] != null){
        grid.SetEditErrorText((string)ViewData["EditError"]);
    }    
}

@grid.Bind(Model).GetHtml()
    